package com.yungu.swift.report.service.impl;

import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.admin.AdminReportParam;
import com.yungu.swift.report.base.service.impl.BaseServiceImpl;
import com.yungu.swift.report.dao.ReportRechargeDayMapper;
import com.yungu.swift.report.entity.ReportOrderFeeDay;
import com.yungu.swift.report.entity.ReportRechargeDay;
import com.yungu.swift.report.service.RechargeDayService;
import com.yungu.swift.utils.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;


/**
 * ReportRechargeDayServiceImpl
 **/
@Component
public class RechargeDayServiceImpl extends BaseServiceImpl<ReportRechargeDay> implements RechargeDayService {
    @Autowired
    private ReportRechargeDayMapper<ReportRechargeDay> reportRechargeDayMapper;

    @Override
    public IMapper<ReportRechargeDay> getMapper() {
        return reportRechargeDayMapper;
    }

    @Override
    public ResponseData<Map<String, Object>> queryPageSubsidy(AdminReportParam reportParam) {
        PageBounds pageBounds = new PageBounds(reportParam.getPageNum(), reportParam.getPageSize());
        if (StringUtils.isNotEmpty(reportParam.getOrderBySort())) {
            pageBounds.setOrders(Order.formString(reportParam.getOrderBySort()));
        }
        PageList<ReportOrderFeeDay> pageList = reportRechargeDayMapper.queryPageSubsidy(reportParam, pageBounds);
        PageVo<ReportOrderFeeDay> pageVo = new PageVo(reportParam.getPageNum(), reportParam.getPageSize(), pageList.getPaginator().getTotalCount());
        pageVo.setItems(pageList);
        Map<String, Object> objectMap = MapUtils.convertObjToMap(pageVo);
        objectMap.put("startTime", reportParam.getStartTime());
        objectMap.put("endTime", reportParam.getEndTime());
        return ResponseData.buildSuccessResponse(objectMap);
    }

    @Override
    public ResponseData<List<ReportRechargeDay>> listSubsidy(AdminReportParam reportParam) {
        return ResponseData.buildSuccessResponse(reportRechargeDayMapper.listSubsidy(reportParam));
    }
}